from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains

# 实例化浏览器驱动
driver = webdriver.Chrome()
# 最大化浏览器
driver.maximize_window()
# 打开百度
driver.get("https://www.baidu.com")
time.sleep(2)

# 鼠标悬停至设置按钮
ActionChains(driver).move_to_element(driver.find_element(By.ID, "s-usersetting-top")).perform()
time.sleep(1)
# 点击-搜索设置
driver.find_element(By.XPATH, "//span[@class='set' and text()='搜索设置']").click()
time.sleep(1)
# 点击-保存设置
driver.find_element(By.XPATH, "//a[text()='保存设置']").click()

# 获取弹出框文本信息
print(driver.switch_to.alert.text)
# 确认弹出框
driver.switch_to.alert.accept()

time.sleep(5)
driver.quit()